package br.org.credfaz.sis.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import br.org.credfaz.sis.MysqlConnectionFactory;
import br.org.credfaz.sis.modelo.AvalFinanceira;

public class AvalFinanceiraDAO {
	
private final Connection connection;
	
	public AvalFinanceiraDAO(){
		try{
			connection = new MysqlConnectionFactory().getConnection();
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
	
	public void adiciona(AvalFinanceira avalfinanceira){
		String sql = "insert into avalfinanceira (idcliente, dataultimaatualizacao," +
				"dataultimarenovacao, valorlimitecreditolongoprazo, valortotalgastofamiliar)" +
				" values (?, ?, ?, ?, ?)";
		PreparedStatement stmt;
		try{
			stmt = connection.prepareStatement(sql);
			
			stmt.setLong(1, avalfinanceira.getIdcliente());
			stmt.setDate(2, avalfinanceira.getDataultimaatualizacao());
			stmt.setDate(3, avalfinanceira.getDataultimarenovacao());
			stmt.setDouble(4, avalfinanceira.getValorlimitecreditolongoprazo());
			stmt.setDouble(5, avalfinanceira.getValortotalgastofamiliar());
						
			stmt.execute();
			
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}

}
